﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Youtube_HD.Model;
using Youtube_HD.Services;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace Youtube_HD.View
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class DetailPlayList : Page
    {
        YoutubeVideo youtubeVideo = null;
        public DetailPlayList()
        {
            this.InitializeComponent();
            this.Loaded += DetailPlayList_Loaded;
            this.NavigationCacheMode = NavigationCacheMode.Required;
        }
        IPlayListViewModel playListViewModel
        {
            get { return (IPlayListViewModel)DataContext; }
        }
        async void DetailPlayList_Loaded(object sender, RoutedEventArgs e)
        {
            loadData.IsActive = true;
            tiltePlayList.Text = "Play List: " + youtubeVideo.Title;
            playListViewModel.YoutubeVideos = null;
            playListViewModel.YoutubeVideosListRelated = null;
            await playListViewModel.GetListDetailPlayList(youtubeVideo.PlayListId);
            loadData.IsActive = false;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>  
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            youtubeVideo = (YoutubeVideo)e.Parameter;

        }

        private void Videos_ItemClick(object sender, ItemClickEventArgs e)
        {
            var getDat = (YoutubeVideo)e.ClickedItem;
            Frame fm = Window.Current.Content as Frame;
            fm.Navigate(typeof(DetailPage), getDat);
        }
    }
}
